package br.com.agiledev.webscrum.entity;

import static javax.persistence.FetchType.LAZY;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;

import org.hibernate.annotations.ForeignKey;

/**
 * Entity implementation class for Entity: ItemRelease
 * 
 */
@Entity
@SequenceGenerator(name = "itemrelease", sequenceName = "se_itemrelease")
@NamedQueries({
    @NamedQuery(name = "ItemRelease.excluirPorItem", query = "delete from ItemRelease ip where ip.item = :item")
})
public class ItemRelease implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(generator = "itemrelease", strategy = GenerationType.SEQUENCE)
    private Long oid;

    @ManyToOne(fetch = LAZY, optional = false)
    @ForeignKey(name = "fk_itemrelease_item")
    private Item item;

    @ManyToOne(fetch = LAZY, optional = false)
    @ForeignKey(name = "fk_itemrelease_release")
    private Release release;

    public ItemRelease() {
	super();
    }

    public ItemRelease(Item item, Release release) {
	setItem(item);
	setRelease(release);
    }

    public Item getItem() {
	return item;
    }

    public Long getOid() {
	return oid;
    }

    public Release getRelease() {
	return release;
    }

    public void setItem(Item item) {
	this.item = item;
    }

    public void setOid(Long oid) {
	this.oid = oid;
    }

    public void setRelease(Release release) {
	this.release = release;
    }

    @Override
    public int hashCode() {
	final int prime = 31;
	int result = 1;
	result = prime * result + ((item == null) ? 0 : item.hashCode());
	result = prime * result + ((release == null) ? 0 : release.hashCode());
	return result;
    }

    @Override
    public boolean equals(Object obj) {
	if (this == obj)
	    return true;
	if (obj == null)
	    return false;
	ItemRelease other = (ItemRelease) obj;
	if (item == null) {
	    if (other.item != null)
		return false;
	} else if (!item.equals(other.getItem()))
	    return false;
	if (release == null) {
	    if (other.release != null)
		return false;
	} else if (!release.equals(other.getRelease()))
	    return false;
	return true;
    }

}